<?php
/**
 * spsNewsletter Default Controller
 * 
 * @author Satyan Shah <joomlaDesign@modernbridge.com>
 * @link http://www.modernbridge.com
 * @license GNU/GPL
 */

// no direct access (security measure)
defined('_JEXEC') or die('Restricted access');

// Require the base controller
require_once (JPATH_COMPONENT.DS.'controller.php');

// Require controller if requested. The controller is set in the views/spsNewsletters/tmpl/default.php file as a hidden input variable
if(($controller = JRequest::getVar('controller'))) {
	require_once (JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php');
}


// Create the controller (in the default case $controller = empty string);
$classname	= 'spsNewslettersController'.$controller;
$controller = new $classname( );

// get the controller name. If there is no controller name specified in the URL set to  the default, sendNewsletter
$specificControllerName = JRequest::getCmd( 'controller', 'sendNewsletter' );

// check if the controller name is something other than the default, if so, render the submenu appropriately
// note: the second argument in the addEntry helper function is weather or not the sub menu item is active

switch($specificControllerName)
{
	case 'subscriber':
		JSubMenuHelper::addEntry(JText::_('Send a Newsletter'), 'index.php?option=com_spsNewsletter');
		// make the subscriber sub-menu heading active
		JSubMenuHelper::addEntry(JText::_('Subscriber Management'), 'index.php?option=com_spsNewsletter&controller=subscriber', true);
		JSubMenuHelper::addEntry(JText::_('Newsletter Management'), 'index.php?option=com_spsNewsletter&controller=newsletter');
		JSubMenuHelper::addEntry(JText::_('spsNewsletter Configuration'), 'index.php?option=com_spsNewsletter&controller=spsNewsletterConfig');
	break;
  
	case 'newsletter':
		JSubMenuHelper::addEntry(JText::_('Send a Newsletter'), 'index.php?option=com_spsNewsletter');
		JSubMenuHelper::addEntry(JText::_('Subscriber Management'), 'index.php?option=com_spsNewsletter&controller=subscriber' );
		// make the newsletter sub-menu heading active
		JSubMenuHelper::addEntry(JText::_('Newsletter Management'), 'index.php?option=com_spsNewsletter&controller=newsletter',true);
		JSubMenuHelper::addEntry(JText::_('spsNewsletter Configuration'), 'index.php?option=com_spsNewsletter&controller=spsNewsletterConfig');
	break;
  
	case 'spsNewsletterConfig':
		JSubMenuHelper::addEntry(JText::_('Send a Newsletter'), 'index.php?option=com_spsNewsletter');
		JSubMenuHelper::addEntry(JText::_('Subscriber Management'), 'index.php?option=com_spsNewsletter&controller=subscriber' );
		JSubMenuHelper::addEntry(JText::_('Newsletter Management'), 'index.php?option=com_spsNewsletter&controller=newsletter');
		// make the newsletterconfig sub menu heading active
		JSubMenuHelper::addEntry(JText::_('spsNewsletter Configuration'), 'index.php?option=com_spsNewsletter&controller=spsNewsletterConfig',true);
	break;
 
	// if we cant resolve the controller or don't recognize it, default to send newsletter
	default:
		// make the sendnewsletter config sub menu heading active
		JSubMenuHelper::addEntry(JText::_('Send a Newsletter'), 'index.php?option=com_spsNewsletter&controller=sendNewsletter',true);
		JSubMenuHelper::addEntry(JText::_('Subscriber Management'), 'index.php?option=com_spsNewsletter&controller=subscriber' );
		JSubMenuHelper::addEntry(JText::_('Newsletter Management'), 'index.php?option=com_spsNewsletter&controller=newsletter');
		JSubMenuHelper::addEntry(JText::_('spsNewsletter Configuration'), 'index.php?option=com_spsNewsletter&controller=spsNewsletterConfig');
	break;
}

// Perform the Request task, The "task" in this case refers to the button pressed.
// i.e. "add", "delete", etc. These functions are defined in 
$controller->execute( JRequest::getVar('task'));

// Redirect if set by the controller
$controller->redirect();

?>
